package com.yantong.service.impl;

import com.yantong.service.BankService;
import com.yantong.utils.PageUtils;
import com.yantong.pojo.Bank;
import com.yantong.pojo.BankBranch;
import com.yantong.mapper.BankMapper;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 银行卡
 * @author baolingyu
 *
 */
@Service
public class BankServiceImpl implements BankService{
	@Autowired
	private BankMapper bankMapper;

	@Override
	public PageUtils<Bank> getListTrunk(int offset, int limit) {
		  PageUtils<Bank> pageUtils = new PageUtils<>();
		  int total = bankMapper.countBank(null);
	        if (total > 0) {
	            List<Bank> list = bankMapper.listBanks(null, new RowBounds(offset, limit));
	            pageUtils.setTotal(total);
	            pageUtils.setRows(list);
	        }
	      return pageUtils;
	}
	
	/**
	 * 主行
	 * @return
	 */
	public List<Bank> getrunkList(){
		return bankMapper.getrunkList(null);
	};
	
	/**
	 * 通过主行查询支行
	 * @param tbCode
	 * @return
	 */
	public List<BankBranch> getBranchList(String tbCode){
		return  bankMapper.getBranchList(tbCode);
	};

	@Override
	public PageUtils<BankBranch> getListBranch(String tbCode, int offset, int limit) {
		 PageUtils<BankBranch> pageUtils = new PageUtils<>();
		  int total = bankMapper.countBranch(tbCode);
	        if (total > 0) {
	            List<BankBranch> list = bankMapper.listBranch(tbCode, new RowBounds(offset, limit));
	            pageUtils.setTotal(total);
	            pageUtils.setRows(list);
	        }
	      return pageUtils;
	}

}
